import type { LoginFormState } from '@/interface/user'
import type { Router } from 'vue-router'
import { userUserStore } from '@/store/modules/user'
import { useGoodsStore } from '@/store/modules/goods'
import { PageNameEnum } from '@/enums/pageEnums'

import { service } from "@/utils/request";
import qs from 'qs'

export function login(data: LoginFormState) {
  return service({
    url: '/login/',
    method: 'POST',
    data: qs.stringify(data)
  })
}

export function logout(navigate: Router) {

  sessionStorage.clear()   // ! 需要放到最上方执行
  const userStore = userUserStore()
  const goodsStore = useGoodsStore()
  userStore.$reset()
  goodsStore.$reset()
  navigate.replace({ name: PageNameEnum.LOGIN })
}


export function getUserList(queryStr: string) {
  return service({
    url: `/userList/?content=${queryStr}`,
    method: 'POST'
  })
}

